package com.example.demo.mapper;

import com.example.demo.model.TorrentComment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TorrentCommentMapper {
    @Select("SELECT id, seed_id, user_id, username, avatar, content, timestamp " +
            "FROM torrent_comment WHERE seed_id = #{seedId} ORDER BY timestamp DESC")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "seedId", column = "seed_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "username", column = "username"),
            @Result(property = "avatar", column = "avatar"),
            @Result(property = "content", column = "content"),
            @Result(property = "timestamp", column = "timestamp")
    })
    List<TorrentComment> findBySeedIdOrderByTimestampDesc(Long seedId);
    @Insert("INSERT INTO torrent_comment (seed_id, user_id, username, avatar, content, timestamp) " +
            "VALUES (#{seedId}, #{userId}, #{username}, #{avatar}, #{content}, #{timestamp})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertComment(TorrentComment comment);
}